# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=grep
pkgver=3.0
pkgrel=2
pkgdesc="A string search utility"
arch=('i686' 'x86_64')
license=('GPL3')
url="https://www.gnu.org/software/grep/"
groups=('base' 'base-devel')
depends=('libiconv' 'libintl' 'libpcre' 'sh')
makedepends=('texinfo' 'gettext-devel' 'libiconv-devel' 'pcre-devel')
install=${pkgname}.install
source=(https://ftp.gnu.org/gnu/${pkgname}/${pkgname}-${pkgver}.tar.xz{,.sig}
        grep-2.23-msys2.patch
        grep-3.0-2.src.patch)
sha256sums=('e2c81db5056e3e8c5995f0bb5d0d0e1cad1f6f45c3b2fc77b6e81435aed48ab5'
            'SKIP'
            '9b9b87f5aa12c49e4e4403d27b85fef3f1de252dfe4eed1a7a4f982ef515a95a'
            '0b2e7e54eb4d5b13257c1b4b43bcb234be02ded8fd04dfbbb73a92346e8b2db2')
validpgpkeys=('155D3FC500C834486D1EEA677FD9FCCB000BEEEE')  # Jim Meyering

prepare() {
  cd ${srcdir}/${pkgname}-${pkgver}

  patch -p1 -i ${srcdir}/grep-2.23-msys2.patch
  # Once this will be commit upstream we need revert it
  #patch -p2 -R -i ${srcdir}/grep-3.0-2.src.patch

  #make test cases work
  sed -i "s|case \$perms in drwx--\[-S\]---\*|case \$perms in drwx\*|" tests/init.sh

  autoreconf -fi
}

build() {
  cd ${srcdir}/${pkgname}-${pkgver}

  echo ${CHOST}
  ./configure \
      --build=${CHOST} \
      --host=${CHOST} \
      --target=${CHOST} \
      --prefix=/usr \
      --without-libiconv-prefix \
      --without-libintl-prefix
  make
}

check() {
  cd ${srcdir}/${pkgname}-${pkgver}
  make check
}

package() {
  cd ${srcdir}/${pkgname}-${pkgver}
  make DESTDIR=${pkgdir} install
}
